<?php
/**
 * Created by PhpStorm.
 * User: godjarvis
 * Date: 2020/08/06
 * Time: 09:39
 */

namespace App\Model\Dao\DangKou;

use App\Model\Entity\DangKou\ProductSize;
use App\Model\Entity\DangKou\ProductSizeFormat;
use App\Model\Entity\DangKou\ProductSizeType;
use App\Model\Entity\DangKou\ProductSkuExtend;
use Fresh\Annotation\Cacheable;
use Fresh\Annotation\ConnectionField;
use Fresh\Mvc\Model\Dao;

class ProductSizeDao extends Dao
{
    /**
     * @Cacheable()
     * @ConnectionField(name="dangkou")
     */
    public function getSizes()
    {
        return $this->expr()
            ->from(ProductSize::class)
            ->orderBy('size_id')
            ->query()
            ->lists('size_id', 'size_name');
    }

    /**
     * @ConnectionField(name="dangkou")
     */
    public function getProductSizes($pid)
    {
        return $this->expr()
            ->from(ProductSkuExtend::class)
            ->where('pid=?', $pid)
            ->query()
            ->lists('size_id');
    }

    /**
     * @Cacheable(lifetime="24h")
     * @ConnectionField(name="dangkou")
     */
    public function getTypes()
    {
        return $this->createQueryBuilder()
            ->from(ProductSizeType::class)
            ->query()
            ->lists('type_id', 'type_name');
    }

    /**
     * 获取款的尺码信息表数据
     * @ConnectionField(name="dangkou")
     */
    public function getByPid($pnid)
    {
        return $this->createQueryBuilder()
            ->from(ProductSizeFormat::class)
            ->where('pnid=?', $pnid)
            ->field('size_id,type_id,format')
            ->query()
            ->find();
    }
}
